//-----------------Sonic CD LightingTrap Script-------------------//
// Yeah...

// Aliases
#alias Object.Value1	:	Object.Timer
#alias Object.Value2	:	Object.Timer2
#alias Object.Value3	:	Object.T1
#alias Object.Value4	:	Object.Timer3
#alias Object.Value5	:	Object.Timer4

#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod

// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

// States
#alias 0	:	LASER_ON
#alias 1	:	LASER_OFF

sub ObjectMain
	if Object.State == LASER_OFF
		Object.Timer++
		if Object.Timer == Object.Timer2
			Object.State = LASER_ON
			Object.T1 = 0
		end if
	end if
end sub

sub ObjectPlayerInteraction
	Object.Timer2 = Object.PropertyValue
	Object.Timer2 *= 30
	if Object.T1 == 1
		Object.State = LASER_OFF
		Object.Timer = 0
		Object.Timer3++
		if Object.Timer3 == 32
			Object.State = LASER_ON
			Object.T1 = 0
			Object.Timer3 = 0
			Object.Timer4 = 0
		end if

		PlayerObjectCollision(C_TOUCH, -72, -16, 72, 0)
		if CheckResult == true
			CallFunction(Player_Hit)
		end if
		
	else
		Object.Timer++
		if Object.Timer == Object.Timer2
			Object.T1 = 1
		end if
	end if
end sub


sub ObjectDraw
	if Object.State == LASER_ON
		DrawSprite(0)
	else
		Object.Timer4++
		
		if Object.Timer4 == 1
			PlayStageSFX(5, false)
		end if
		if Object.Timer4 < 8
			DrawSprite(1)
		else
			if Object.Timer4 < 16
				DrawSprite(1)
				DrawSprite(2)
				DrawSprite(4)
			else
				if Object.Timer4 < 24
					DrawSprite(0)
					DrawSprite(2)
					DrawSprite(3)
					DrawSprite(4)
					DrawSprite(5)
				else
					if Object.Timer4 < 33
						DrawSprite(0)
						DrawSprite(3)
						DrawSprite(5)
					end if
				end if
			end if
		end if
	end if
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects2.gif")
	
	
	TempValue0 = HUD.CurrentTimePeriod
	TempValue1 = 1
	TempValue0 *= 34
	TempValue1 += TempValue0 
	TempValue2 = 17
	TempValue2 += TempValue1
	
	SpriteFrame(-8, -16, 16, 32, TempValue1, 215)			// #0 
	SpriteFrame(-8, -16, 16, 32, TempValue2, 215)			// #1 
	SpriteFrame(-40, -16, 32, 16, 137, 231)					// #2 
	SpriteFrame(-72, -16, 32, 16, 137, 231)					// #3 
	SpriteFrame(8, -16, 32, 16, 137, 231)					// #2 
	SpriteFrame(40, -16, 32, 16, 137, 231)					// #3 
end sub 

// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
	DrawSprite(1)
	DrawSprite(2)
end sub


sub RSDKLoad
	LoadSpriteSheet("R2/Objects2.gif")
	SpriteFrame(-8, -16, 16, 32, 1, 215)			// #0 
	SpriteFrame(-40, -16, 32, 16, 137, 231)			// #1 
	SpriteFrame(8, -16, 32, 16, 137, 231)			// #2

	SetVariableAlias(ALIAS_VAR_PROPVAL, "delay")
end sub